package com.itheima.dao.system;

import com.itheima.domain.system.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/***
 * 平台系统管理 - > 角色管理
 */
public interface RoleDao {
    @Select("select * from ss_role")
    @Results(id = "roleMap",value = {
            @Result(column = "role_id",property = "id",jdbcType = JdbcType.VARCHAR),
            @Result(column = "name",property = "name",jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark",property = "remark",jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time",property = "createTime",jdbcType = JdbcType.TIMESTAMP),
    })
    List<Role> findAll() throws Exception;

    @Select("select * from ss_role where role_id = #{roleId}")
    @ResultMap("roleMap")
    Role findById(String roleId) throws Exception;

    @Insert("INSERT INTO ss_role (role_id, NAME, remark, create_time) VALUES (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})")
    int save(Role role) throws Exception;

    @Update("UPDATE ss_role SET NAME = #{name,jdbcType=VARCHAR}, remark = #{remark,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP} WHERE role_id = #{id,jdbcType=VARCHAR}")
    int update(Role role)throws Exception;

    @Delete("delete from ss_role  where role_id = #{id,jdbcType=VARCHAR}")
    int deleteById(String roleId)throws Exception;

    @Delete("delete from ss_role_module where role_id = #{xx}")
    int deleteModuleByRoleId(String roleId)throws Exception;

    /**
     * 绑定角色和模块的关系
     * @param moduleId
     * @param roleId
     * @return
     * @throws Exception
     */
    @Insert("insert into ss_role_module(role_id,module_id) values(#{r},#{m)")
    int saveModuleAndRole(@Param("m")String moduleId,@Param("r")String roleId)throws Exception;
}
